<div class="row-fluid">
	<div class="span12">
		<ul class="breadcrumb">
			<li>
				<a href="index.php">
					<i class="radmin-icon radmin-home"></i>
					Dashboard
				</a>
				<span class="divider">/</span>
			</li>
			<li>
				<a href="whm-accounts.php">
					<i class="radmin-icon radmin-clipboard-2"></i>
					WHM Accounts
				</a>
				<span class="divider">/</span>
			</li>
			<li class="active">
				<i class="radmin-icon radmin-clipboard"></i>
				cPanel Accounts
			</li>
		</ul>
	</div>
</div>

<div class="row-fluid">
	<div class="span12">
		<h4 class="title">
			<?php $this->widget('application.components.mywidgets.WikiHelp', array('wiki' => 'cpanel_accounts')); ?>
			cPanel Accounts | <?php echo $whmaccount->domain; ?>
		</h4>
		<h5 class="pull-right">
			Last Updated: <?php echo date('y F d H:i', $whmaccount->last_cp_update); ?>
			( <a href="<?php echo url('whm/cpanelaccount/index', array('id_account' => $whmaccount->id_account, 'reload' => 1)); ?>">Pull Fresh cPanel Data</a> )
		</h5>
		<div class="squiggly-border"></div>
		<?php if(!empty($errors)): ?>
			<div class="alert alert-info">
				<?php foreach($errors as $k => $es): ?>
					<?php foreach($es as $e): ?>
						<p><?php echo $k; ?>: <?php echo $e; ?></p>
					<?php endforeach; ?>
				<?php endforeach; ?>
			</div>
		<?php endif; ?>
		
		<?php $form = $this->beginWidget('CActiveForm', array(
			'id' => 'cpanelaccount-list-form',
			'method' => 'get'
		)); ?>
			<?php $this->widget('zii.widgets.grid.CGridView', array(
				'id' => 'cpanelaccount_grid',
				'summaryText' => '',
				'dataProvider' => new CArrayDataProvider(
					$whmaccount->CpanelAccounts, array(
						'keyField' => 'id_cpanel_accounts', 
						'sort' => array(
							'defaultOrder'=>'domain ASC',
							'attributes' => array(
								'domain_sort' => array(
									'asc' => 'domain',
									'desc' => 'domain DESC',
								),
								'username_sort' => array(
									'asc' => 'username ',
									'desc' => 'username DESC',
								),
								'whmaccount_sort' => array(
									'asc'=>'',				// TODO: how?
									'desc'=>'',
								),
								'package_sort' => array(
									'asc' => 'package',
									'desc' => 'package DESC',
								),
								'owner_sort' => array(
									'asc' => 'owner',
									'desc' => 'owner DESC',
								),
							)
						),
						'pagination' => array(
							'pageSize'=> app()->user->getData()->getIndividualConfig()->getPagination()
						)
					)),
				'columns' => array(
					array(
						'header' => 'Id',
						'value' => '$data->id_cpanel_accounts',
						'headerHtmlOptions' => array('class' => 'hide'),
						'htmlOptions' => array('class' => 'hide id_cpanel_accounts')
					),
					array(
						'header' => '',
						'type' => 'raw',
						'value' => 'CHtml::checkBox("cpanel_accounts[checked][]", false, array("class" => "cpanelaccounts_check"))'
					),
					array(
						'header' => 'Domain', 
						'value' => '$data->domain',
						'headerHtmlOptions' => array('class' => 'domain_sort'),
						'name' => 'domain_sort',
						'sortable' => true
					),
					'IP',
					array(
						'header' => 'Username', 
						'value' => '$data->username',
						'headerHtmlOptions' => array('class' => 'username_sort'),
						'name' => 'username_sort',
						'sortable' => true
					),
					array(
						'header' => 'Setup Date', 
						'value' => '$data->setup_date',
						'headerHtmlOptions' => array('class' => 'hidden-phone'),
						'htmlOptions' => array('class' => 'hidden-phone')
					),
					array(
						'header' => 'WHM Account', 
						'value' => '$data->WhmAccount->domain',
						'htmlOptions' => array('class' => 'hidden-phone'),
						'headerHtmlOptions' => array('class' => 'whmaccount_sort hidden-phone'),
						'name' => 'whmaccount_sort',
						'sortable' => true
					),
					array(
						'header' => 'Quota', 
						'value' => '$data->quota',
						'headerHtmlOptions' => array('class' => 'hidden-phone'),
						'htmlOptions' => array('class' => 'hidden-phone')
					),
					array(
						'header' => 'Disk Used', 
						'value' => '$data->disk_used',
						'headerHtmlOptions' => array('class' => 'hidden-phone'),
						'htmlOptions' => array('class' => 'hidden-phone')
					),
					array(
						'header' => 'Package', 
						'value' => '$data->package',
						'htmlOptions' => array('class' => 'hidden-phone'),
						'headerHtmlOptions' => array('class' => 'package_sort hidden-phone'),
						'name' => 'package_sort',
						'sortable' => true
					),
					array(
						'header' => 'Theme', 
						'value' => '$data->theme',
						'headerHtmlOptions' => array('class' => 'hidden-phone'),
						'htmlOptions' => array('class' => 'hidden-phone')
					),
					array(
						'header' => 'Owner', 
						'value' => '$data->owner',
						'htmlOptions' => array('class' => 'hidden-phone'),
						'headerHtmlOptions' => array('class' => 'owner_sort hidden-phone'),
						'name' => 'owner_sort',
						'sortable' => true
					),
				),
				'itemsCssClass' => 'table table-index table-striped',
				'pagerCssClass' => 'pagination pagination-right',
				'pager' => array(
					'class' => 'LinkPager',
					
					
					
				),
				'htmlOptions' => array(
					'class' => ''
				)
			));?>
			<script>
				var sort = <?php echo json_encode($sort); ?>;
				sort = sort.split('.');
				if(sort[1] == 'desc'){
					var arrow = $('<i class="icon-arrow-down hidden-phone"></i>');
				}else{
					var arrow = $('<i class="icon-arrow-up hidden-phone"></i>');
				}
				$('#cpanelaccount_grid th.'+sort[0]).append(arrow);
			</script>
			
			<span class="pull-left">
				<input id="cpanelaccounts_check_all" type="checkbox">
				<script>
					$('#cpanelaccounts_check_all').click(function(){
						$('.cpanelaccounts_check').removeAttr('checked');
						if($(this).is(":checked")){
							$('.cpanelaccounts_check').attr('checked', true);
						}
					});
	
					$('.cpanelaccounts_check').live('click', function(){
						$('#cpanelaccounts_check_all').attr('checked', true);
						$('.cpanelaccounts_check').each(function(k, v){
							if(!$(v).is(":checked")){
							$('#cpanelaccounts_check_all').removeAttr('checked');
								return true;
							}
						});
					});
				</script>
				<?php echo CHtml::dropDownList('cpanel_accounts[event]', '', array(
					'passwords' => 'Change Passwords', 
					'modify' => 'Modify Accounts',
					'bandwidth' => 'Change Bandwidth',
					'suspend' => 'Suspend Accounts',
					'unsuspend' => 'Unsuspend Accounts',
					'terminate' => 'Terminate Accounts'
				)); ?>
				<?php echo CHtml::tag('button', array('class' => 'btn', 'id' => 'event_go', 'type' => 'submit'), 'Go'); ?>
				<script>
					$('#event_go').click(function(){
						$('.cpanelaccounts_check').each(function(k, v){
							if($(v).is(":checked")){
								var username = $(v).parents('tr').find('.id_cpanel_accounts').text();
								$(v).val(username);
							}
						});

						$('#cpanelaccount-list-form').attr('action', '/whm/cpanelaccount/'+$('#cpanel_accounts_event').val());
					});
				</script>
			</span>
		<?php $this->endWidget(); ?>
	</div>
</div>